package Demo3;

public class Main17 {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
           while (Thread.currentThread().isInterrupted()){
               System.out.println("hello thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   break;
               }
           }
        });
        System.out.println("start之前的状态："+t.getState());
        t.start();
        System.out.println("start之后的状态："+t.getState());
        System.out.println("main线程尝试终止t线程结束");
        t.interrupt();
        System.out.println("主线程结束");
    }
}
